sap.ui.define([], () => {
	"use strict";

	return {

		returnDate(timestamp) {
			if (timestamp) {
				var date = new Date(timestamp);
				return sap.ui.core.format.DateFormat.getDateTimeInstance({ pattern: "yyyy/MM/dd HH:mm:ss" }).format(date).slice(0, 10);
			} else {
				return "";
			}
		},

		returnTime(timestamp) {
			if (timestamp) {
				var date = new Date(timestamp);
				return sap.ui.core.format.DateFormat.getDateTimeInstance({ pattern: "yyyy/MM/dd HH:mm:ss" }).format(date).slice(11, 19);
			} else {
				return "";
			}
		},

		objectTransformToList(obj) {
			let list = [];
			for (var key in obj) {
				if (obj.hasOwnProperty(key)) {
					list.push(obj[key]);
				}
			}
			return list;
		},

		transformDate(date) {
			// var date = new Date("Thu Jul 20 2023 08:00:00 GMT+0800 (中国标准时间)");
			if (date) {
				var year = date.getFullYear();
				var month = ("0" + (date.getMonth() + 1)).slice(-2);
				var day = ("0" + date.getDate()).slice(-2);
				var hours = ("0" + date.getHours()).slice(-2);
				var minutes = ("0" + date.getMinutes()).slice(-2);
				var seconds = ("0" + date.getSeconds()).slice(-2);

				var formattedDate = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;

				return formattedDate;
			} else {
				return "";
			}
		},

		test() {
			console.log("test");
		},

		removeNestedObjects(list) {
			var that = this;
			var filteredList = list.map(function (obj) {
				// 获取对象的所有属性
				var keys = Object.keys(obj);

				// 过滤掉属性类型为对象的属性
				var filteredObj = keys.reduce(function (result, key) {
					if (typeof obj[key] !== 'object') {
						result[key] = obj[key];
					} else {
						if (obj[key] instanceof Date) {
							result[key] = that.transformDate(obj[key]);
						}
						if (obj[key] == null) {
							result[key] = "";
						}
					}
					return result;
				}, {});

				return filteredObj;
			});
			return filteredList;
		},

		filterSource(obj, value) {
			var newObj = Object.keys(obj).reduce(function (result, key) {
				if (key.indexOf(value) !== -1) {
					result[key] = obj[key];
				}
				return result;
			}, {});
			return newObj;
		},
	};
});